package cn.ibizlab.odoo.core.odoo_website.service.impl;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.HashMap;
import java.math.BigInteger;
import java.util.Collection;

import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cglib.beans.BeanCopier;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import cn.ibizlab.odoo.core.client.model.Iwebsite_seo_metadata;
import cn.ibizlab.odoo.core.odoo_website.domain.Website_seo_metadata;
import cn.ibizlab.odoo.core.odoo_website.filter.Website_seo_metadataSearchContext;
import cn.ibizlab.odoo.core.odoo_website.service.IWebsite_seo_metadataService;
import cn.ibizlab.odoo.util.SearchResult;
import cn.ibizlab.odoo.util.log.IBIZLog;

/**
 * 实体[SEO元数据] 服务对象接口实现
 */
@Slf4j
@IBIZLog
@Service
public class Website_seo_metadataServiceImpl implements IWebsite_seo_metadataService {

    @Autowired
    private cn.ibizlab.odoo.core.client.service.Iwebsite_seo_metadataClientService website_seo_metadataClientService;

    @Override
    public boolean create(Website_seo_metadata website_seo_metadata) {
        boolean bOk = false ;
        Iwebsite_seo_metadata clientModel = this.convert2Model(website_seo_metadata,null);
        website_seo_metadataClientService.create(clientModel) ;
        this.convert2Domain(clientModel,website_seo_metadata);
        bOk = true ;

        return bOk ;
    }

    @Override
    public void createBatch(List<Website_seo_metadata> website_seo_metadatas, int batchSize) {

                        //website_seo_metadataClientService.createBatch(website_seo_metadatas,batchSize) ;

    }

    @Override
    public void updateBatch(List<Website_seo_metadata> website_seo_metadatas, int batchSize) {

        //website_seo_metadataClientService.updateBatch(website_seo_metadatas,batchSize) ;

    }

    @Override
    public boolean update(Website_seo_metadata website_seo_metadata) {
        boolean bOk = false ;
        Iwebsite_seo_metadata clientModel = this.convert2Model(website_seo_metadata,null);
        website_seo_metadataClientService.update(clientModel) ;
        this.convert2Domain(clientModel,website_seo_metadata) ;
        bOk = true;
        return bOk ;
    }

    @Override
    public Website_seo_metadata get(Integer id) {
        Iwebsite_seo_metadata clientModel = website_seo_metadataClientService.createModel();
        clientModel.setId(id);
        website_seo_metadataClientService.get(clientModel) ;
        return this.convert2Domain(clientModel,null);
    }

    @Override
    public Website_seo_metadata get(Website_seo_metadata website_seo_metadata) {
        Website_seo_metadata retwebsite_seo_metadata = this.get(website_seo_metadata.getId()) ;
    	BeanCopier copier=BeanCopier.create(retwebsite_seo_metadata.getClass(), website_seo_metadata.getClass(), false);
        copier.copy(retwebsite_seo_metadata, website_seo_metadata, null);
        return website_seo_metadata ;
    }

    @Override
    public void removeBatch(Collection<? extends Serializable> idList, int batchSize) {

        //website_seo_metadataClientService.removeBatch(website_seo_metadatas) ;

    }

    @Override
    public boolean remove(Integer id) {
        boolean bOk = false ;
        Iwebsite_seo_metadata clientModel = website_seo_metadataClientService.createModel();
        clientModel.setId(id);
        website_seo_metadataClientService.remove(clientModel) ;
        bOk = true ;
        return bOk ;
    }

    /**
     * 查询集合 默认查询
     */
    @Override
    public Page<Website_seo_metadata> searchDefault(Website_seo_metadataSearchContext context) {
        List<Website_seo_metadata> list = new ArrayList<Website_seo_metadata>();
        Page<cn.ibizlab.odoo.core.client.model.Iwebsite_seo_metadata> clientModelList = website_seo_metadataClientService.search(context) ;
        for(cn.ibizlab.odoo.core.client.model.Iwebsite_seo_metadata clientModel : clientModelList){
            list.add( this.convert2Domain(clientModel,null));
        }
        return new PageImpl<Website_seo_metadata>(list, context.getPageable(), clientModelList.getTotalElements());
    }




    public Iwebsite_seo_metadata convert2Model(Website_seo_metadata domain , Iwebsite_seo_metadata model) {
        if(domain == null)
            return model ;
        if(model==null){
            model = website_seo_metadataClientService.createModel() ;
        }

         if(domain.getDisplay_nameDirtyFlag())
            model.setDisplay_name(domain.getDisplay_name());
         if(domain.getIdDirtyFlag())
            model.setId(domain.getId());
         if(domain.getWebsite_meta_og_imgDirtyFlag())
            model.setWebsite_meta_og_img(domain.getWebsite_meta_og_img());
         if(domain.getWebsite_meta_titleDirtyFlag())
            model.setWebsite_meta_title(domain.getWebsite_meta_title());
         if(domain.getWebsite_meta_keywordsDirtyFlag())
            model.setWebsite_meta_keywords(domain.getWebsite_meta_keywords());
         if(domain.get__last_updateDirtyFlag())
            model.set__last_update(domain.get__last_update());
         if(domain.getWebsite_meta_descriptionDirtyFlag())
            model.setWebsite_meta_description(domain.getWebsite_meta_description());
         if(domain.getIs_seo_optimizedDirtyFlag())
            model.setIs_seo_optimized(domain.getIs_seo_optimized());
        return model ;
    }

    public Website_seo_metadata convert2Domain( Iwebsite_seo_metadata model ,Website_seo_metadata domain) {
        if(model == null)
            return domain ;
        if(domain == null){
            domain = new Website_seo_metadata();
        }

        if(model.getDisplay_nameDirtyFlag())
            domain.setDisplay_name(model.getDisplay_name());
        if(model.getIdDirtyFlag())
            domain.setId(model.getId());
        if(model.getWebsite_meta_og_imgDirtyFlag())
            domain.setWebsite_meta_og_img(model.getWebsite_meta_og_img());
        if(model.getWebsite_meta_titleDirtyFlag())
            domain.setWebsite_meta_title(model.getWebsite_meta_title());
        if(model.getWebsite_meta_keywordsDirtyFlag())
            domain.setWebsite_meta_keywords(model.getWebsite_meta_keywords());
        if(model.get__last_updateDirtyFlag())
            domain.set__last_update(model.get__last_update());
        if(model.getWebsite_meta_descriptionDirtyFlag())
            domain.setWebsite_meta_description(model.getWebsite_meta_description());
        if(model.getIs_seo_optimizedDirtyFlag())
            domain.setIs_seo_optimized(model.getIs_seo_optimized());
        return domain ;
    }


}
